package ws.very.util.dingtalk.encryptor

object DingTalkEncryptException {
  /** 成功 **/
  val SUCCESS: Int = 0
  /** 加密明文文本非法 **/
  val ENCRYPTION_PLAINTEXT_ILLEGAL: Int = 900001
  /** 加密时间戳参数非法 **/
  val ENCRYPTION_TIMESTAMP_ILLEGAL: Int = 900002
  /** 加密随机字符串参数非法 **/
  val ENCRYPTION_NONCE_ILLEGAL: Int = 900003
  /** 不合法的aeskey **/
  val AES_KEY_ILLEGAL: Int = 900004
  /** 签名不匹配 **/
  val SIGNATURE_NOT_MATCH: Int = 900005
  /** 计算签名错误 **/
  val COMPUTE_SIGNATURE_ERROR: Int = 900006
  /** 计算加密文字错误 **/
  val COMPUTE_ENCRYPT_TEXT_ERROR: Int = 900007
  /** 计算解密文字错误 **/
  val COMPUTE_DECRYPT_TEXT_ERROR: Int = 900008
  /** 计算解密文字长度不匹配 **/
  val COMPUTE_DECRYPT_TEXT_LENGTH_ERROR: Int = 900009
  /** 计算解密文字corpid不匹配 **/
  val COMPUTE_DECRYPT_TEXT_CORPID_ERROR: Int = 900010
  private val msgMap = Map(
    (SUCCESS, "成功"),
    (ENCRYPTION_PLAINTEXT_ILLEGAL, "加密明文文本非法"),
    (ENCRYPTION_TIMESTAMP_ILLEGAL, "加密时间戳参数非法"),
    (ENCRYPTION_NONCE_ILLEGAL, "加密随机字符串参数非法"),
    (SIGNATURE_NOT_MATCH, "签名不匹配"),
    (COMPUTE_SIGNATURE_ERROR, "签名计算失败"),
    (AES_KEY_ILLEGAL, "不合法的aes key"),
    (COMPUTE_ENCRYPT_TEXT_ERROR, "计算加密文字错误"),
    (COMPUTE_DECRYPT_TEXT_ERROR, "计算解密文字错误"),
    (COMPUTE_DECRYPT_TEXT_LENGTH_ERROR, "计算解密文字长度不匹配"),
    (COMPUTE_DECRYPT_TEXT_CORPID_ERROR, "计算解密文字corpid或者suiteKey不匹配")
  )

  def getMsg(code: Int) = {
    msgMap(code)
  }
}

case class DingTalkEncryptException(code: Int) extends Exception(DingTalkEncryptException.getMsg(code))
